<?php
if(!defined("IN_PHPSCUP"))exit("hacking");
class UserPower
{

  var  $filename = "";
  
  var   $usermsg= "";//用户信息
  
  var   $powerdata= "";//
  

 function __construct($filename,&$usermsg = null)
    {	
	
        $this->UserPower($filename,$usermsg);
				
    }
	   
 function UserPower($filename,&$usermsg)
    {	
	
        $this->filename = $filename;	
        $this->usermsg = &$usermsg;	
	
	}
	
 //用户组权限判断
 function Power($app,$act)
    {
	
        $this->GetPowerData();
		
        $this->_Power($app,$act);
	
        $this->PersonPower();
	
	}
	

 //用户组权限判断
 function _Power($app,$act)
    {
	    if(!isset($this->usermsg['user_id']))
		{
		 $this->usermsg['user_id'] = 0;
		}
	    if(!isset($this->usermsg['data']))
		{
		 $this->usermsg['data'] = array();
		}		
	    if(!isset($this->usermsg['data']['role_id']))
		{
		 $this->usermsg['data']['role_id'] = ROLE_Y_ID;//默认为游客组
		}		  	 
		    
	    if($this->usermsg['user_id']==0)
		{

		 $this->usermsg['data']['role_id'] = ROLE_Y_ID;//默认为游客组
		
		}

		$role_array = role_deal($this->usermsg['data']['role_id']);
		
		$role_id = $role_array[$GLOBALS['SCup']->SCup_name];		


	    if(!isset($this->powerdata[$role_id]))
		{
		 $notice = &get_message(array('msg'=>'no exist powerdata','url'=>'','title'=>'Notice'));
		 $notice ->display();		
		}	
		

		
		if(!(isset($this->powerdata[$role_id]['powerdb'][$app]) && isset($this->powerdata[$role_id]['powerdb'][$app][$act]) && isset($this->powerdata[$role_id]['powerdb'][$app][$act]['set']) && $this->powerdata[$role_id]['powerdb'][$app][$act]['set']==1))
		{
			if($this->usermsg['user_id']==0)
			{
				if($GLOBALS['SCup']->SCup_name == 'admin')
				{
					$notice = &get_message(array('msg'=>'你没有登录!','url'=>'index.php?app=default&act=login', 'taget'=>'top', 'title'=>'Notice'));
		 		 	$notice ->display();	
				}else
				{
					$notice = &get_message(array('msg'=>'你没有登录!','url'=>'?app=login&act=index','title'=>'Notice'));
		 		 	$notice ->display();	
				}
			}else
			{
			     if(!isset($this->powerdata[$role_id]['powerdb'][$app][$act]['url']))
				 {
				 $this->powerdata[$role_id]['powerdb'][$app][$act]['url'] = '';
				 }
				 $notice = &get_message(array('msg'=>'用户无此权限!','url'=>$this->powerdata[$role_id]['powerdb'][$app][$act]['url'],'title'=>'Notice'));
		 		$notice ->display();	
			}		 
		}
		$GLOBALS['SCup']->SCup_user_msg['role_name'] =  $this->powerdata[$role_id]['role_name'];			
			           
	}


	
	

  //单个用户权限判断
 function PersonPower()
    {
	
  
	
	
	
	}
	

  //
 function GetPowerData()
    {	     	  
		if(empty($this->filename))
	    {
		 $this->filename = ROOT_PATH . '/data/power/'.$GLOBALS['SCup']->SCup_name.'.power.php'; 			 
		}		
		
		if(is_file($this->filename))
	    {
	    $this->powerdata = include($this->filename); 
		}
		else
	    {
        exit('Missing PowerFile');
		}  
	
	}

}



?>